#pragma once

#include "Business/Business.h"
#include "StatusMachine/StatusMachine.h"

class Customer;
class MarketStorage;
class QueueContext;
class DealingRepository;
class CancellationRepository;
class ClassicBusinessArgument;
class ClassicBusinessContext;
class BollingerCalculatorManager;
class Bollingers;

struct ClassicBusinessSnapshot
{
	char const* statusName;
	int minorDirection;
	int majorPosition;
	int minorPosition;
	double profit;
	bool operator==(ClassicBusinessSnapshot const& other) const
	{
		return statusName == other.statusName && minorDirection == other.minorDirection &&
			majorPosition == other.majorPosition && minorPosition == other.minorPosition &&
			DoubleEqual(profit,other.profit);
	}
	bool operator!=(ClassicBusinessSnapshot const& other) const
	{
		return !operator==(other);
	}
};

class ClassicBusiness : public AutoUpdateUIBusiness<ClassicBusiness>
{
public:
	typedef ClassicBusinessArgument Argument;
	typedef ClassicBusinessSnapshot Snapshot;
public:
	ClassicBusiness(Customer& customer,ClassicBusinessArgument const& argument,
		BollingerCalculatorManager& bollingerManager,
		MarketStorage const& marketStorage,
		QueueContext& queueContext,
		DealingRepository& dealingRepository,
		CancellationRepository& cancellationRepository);

	ClassicBusinessArgument const& GetArgument() const;
	bool IsEditStatus() const;
	ClassicBusinessSnapshot GetSnapshot() const;
	void UpdateUI(ClassicBusinessSnapshot const& snapshot);
private:
	virtual void DoOnInit();
	virtual void DoOnMarket(Market const& market);
	virtual void DoOnPendingMarket(PendingMarket const& pendingMarket);
	virtual void DoOnDealing(Dealing const& dealing);
	virtual void DoOnTimeout(RequestTimeout const& requestTimeout);
	virtual void DoOnTrade(Trade const& trade);
	virtual void DoOnCommand(Command const& command);
	virtual void DoOnExchangeStatus(int exchangeStatus);

	void UpdateArgument(ClassicBusinessArgument &argument);

	BollingerCalculatorManager& m_bollingerManager;
	QueueContext& m_queueContext;
	DealingRepository& m_dealingRepository;
	CancellationRepository& m_cancellationRepository;
	std::auto_ptr<ClassicBusinessContext> m_context;
	Bollingers const* m_bollingers;

};